#include "customvertex.h"
#include "ground.h"
#include "string.h"

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_TEX1)

#define  NUM_VERTSGROUND 8
#define  BOTTOMHALFOFFSET 4

static int GroundIDCounter = 1;

CUSTOMVERTEX g_Verticies[] =
	{
			{-5.0f,-1.41f, 1.0f,  0.0f,0.0f },	// ground
			{ 5.0f,-1.41f, 1.0f,  1.0f,0.0f },
			{-5.0f,-1.41f,-1.0f,  0.0f,1.0f },
			{ 5.0f,-1.41f,-1.0f,  1.0f,1.0f },

			{-5.0f,-1.41f,-1.0f,  0.0f,0.0f },	// ground
			{ 5.0f,-1.41f,-1.0f,  1.0f,0.0f },
			{-5.0f,-2.82f,-1.0f,  0.0f,1.0f },
			{ 5.0f,-2.82f,-1.0f,  1.0f,1.0f },
	};

int ground::setupVB(CUSTOMVERTEX *v_buff,int count)
{
	ID = GroundIDCounter;
	GroundIDCounter++;

    memcpy( v_buff, g_Verticies, sizeof(CUSTOMVERTEX)*NUM_VERTSGROUND );
	mycount = count;

	if(ID == 1)
	{
		transY = 0.0;
		transX = 0.0;
	}
	else if(ID == 2)
	{
		transY = 3.0;
		transX = 12.0;
	}
	else if (ID == 3)
	{
		transY = 6.0;
		transX = 24.0;
	}

	return count+NUM_VERTSGROUND;
	
}

void ground::draw(LPDIRECT3DDEVICE9 *pd3dDevice, LPDIRECT3DTEXTURE9 * g_pTexture2)
{
	(*pd3dDevice)->SetTexture( 0, *g_pTexture2 );
	(*pd3dDevice)->DrawPrimitive( D3DPT_TRIANGLESTRIP,  mycount, 2 );
	(*pd3dDevice)->DrawPrimitive( D3DPT_TRIANGLESTRIP,  mycount+BOTTOMHALFOFFSET, 2 );
}